data, for example: "hahaha", "abcdef" ... Note: A Chinese character in the database of how many bytes, to see the Unicode encoding, such as: UTF8 on MySQL accounted for 3 bytes, SQL Server chinese_prc_ci_as accounted for 2 bytes ...2).nvarchar: Store data by characternvarchar(6), can store up to 6 characters/Chinese data, such as: "Haha haha", "abcdef" ...nvarchar(m) The actual byte length of the maximum storage=N*M (n depends on encoding), if the nv
, 2009 Monday pm) According to ' date of month, day of the week, morning afternoon 'Select Datename (Yy,getdate ()) + ' year ' +Datename (Mm,getdate ()) + ' month ' +Datename (Dd,getdate ()) + ' Day ' +Datename (Weekday,getdate ()) +Case when Datename (Hh,getdate ()) --2. Write the function, depending on the input time. The day of the year is outputSelect DATEPART (dy,getdate ())--3. Finding random output characters ' A-ZSelect char (97+abs (checksum (NEWID))%26)Select char (97+rand () *26)
Differences between varchar and nvarchar:
Varchar (n)Variable-length and non-Unicode character data with a length of n Bytes. N must be a value between 1 and 8,000. The storage size is the actual length of the input data bytes, rather than n Bytes (such as varchar (6). When the field is qqq, the actual space occupied by the database is 3 bytes, instead of 6 bytes
This article describes in detail the performance and space occupied by varchar (n) and nvarchar (n) in SQL. For more information, see.
This article describes in detail the performance and space occupied by varchar (n) and nvarchar (n) in SQL. For more information, see.
How to explain n in
Differences between varchar and nvarchar:
Varchar (N)Variable-length and non-UNICODE character data with a length of n Bytes. N must be a value between 1 and 8,000. The storage size is the actual length of the input data bytes, rather than n Bytes (such as varchar (6). When the field is qqq, the actual space occupied by the database is 3 bytes, instead of 6 byt
character set is to solve the character set this incompatibility problem, all of its characters are expressed in two bytes, That is, the English character is also represented in two bytes. The length of the nchar and nvarchar is between 1 and 4000. Compared to char and varchar, nchar and nvarchar store up to 4,000 characters, whether in English or Chinese characters, while char and varchar can store up to
character sets, all of its characters are represented by two bytes, That is, the English character is also represented in two bytes.(5) A brief introduction to Var:With the Var prefix, it means that the actual storage space is getting longer, Varchar,nvarchar The so-called length is fixed, when the input length of the data does not reach the specified length will be automatically filled with English space after it, so that the length of the correspon
type do not worry about the input characters are English or Chinese characters, more convenient, but in the storage of English number of some losses.So generally, if it contains Chinese characters, use Nchar/nvarchar, if pure English and numbers, with Char/varcharTheir differences are summarized as follows:Char, nchar fixed length, high speed, occupy space, need to handlevarchar, nvarchar, text variable length, small space, slow speed, no processingnchar, nvarchar, ntext processing Unicode code
VARCHAR (n)
A variable length of n bytes and non-Unicode character data. n must be a numeric value between 1 and 8,000. The actual length of the byte that the storage size is the input data, not the N bytes.
nvarchar (n)
Variable-length Unicode character data containing n characters. The value of n must be between 1 and 4,000. The storage size of bytes is twice times the number of characters entered.
Two fields have field values: coffee and I
The
Differences between varchar and nvarchar:
Varchar (N)Variable-length and non-UNICODE character data with a length of n Bytes. N must be a value between 1 and 8,000. The storage size is the actual length of the input data bytes, rather than n Bytes (such as varchar (6). When the field is qqq, the actual space occupied by the database is 3 bytes, instead of 6 byte
could be retired by SQL Server, but it was not clear why the difference between text and varchar (max) and nvarchar (max) was found in reading today, mainly the restriction of operators. Text can only be used by the following functions:
function
Statement
Datalength
READTEXT
PATINDEX
SET TEXTSIZE
SUBSTRING
UpdateText
sql| Difference |varchar| field type
What is the difference between nvarchar and varchar in SQL Server 2000?
SQL Server provides two types of data to store character information. The two data types are roughly the same in how they are used in
("abc ").Varchar is slightly less efficient than char because, when modifying varchar data, data migration (that is, redundant I/O) may be caused by different data lengths ). Oracle expresses this redundant I/O description as "Row Migration ).View instancesChar and varchar of SQL SERVER 2000 in this Tes
for Chinese and other characters, where n represents a Unicode constant, which resolves the problem of conversion between multilingual character sets.
The following are supplementary:
For fields with generic string types in your program, there are four types of char, varchar, nchar, and nvarchar in SQL Server, so what's the difference between these four types?
1. Fixed-length or variable-length
The so
In SQL, the varchar type is converted to int and then sorted, if our database ID is set to varchar type, the order by ID when queried.If the ID of our database is set to the varchar type of the order by ID at the time of the query, we do not want to see the following situation.We can convert
first, let's look at the instructions in the official help of nvarchar and varchar:varchar (n)Variable-length, non-Unicode character data with a length of n bytes. n must be a numeric value between 1 and 8,000. Storage size is the actual length of bytes of input data, not n bytes. The input data character length can be zero. The synonym for varchar in SQL-92 is char varying or character varying.nvarchar (n)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.